package com.whp.yky.yky.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.whp.yky.yky.entity.ShopGoods;
import com.whp.yky.yky.response.ResponseData;
import com.whp.yky.yky.service.impl.ShopGoodsServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@Api(tags = "商品接口")
@CrossOrigin
@RestController
public class ShopGoodsController {

    @Autowired
    private ShopGoodsServiceImpl shopGoodsService;


    @ApiOperation(value="获取所有商品", notes="获取所有商品")
    @PostMapping("/getShopGoodsInfo")
    public ResponseData getShopGoodsInfo(@RequestBody ShopGoods shopGoods, @RequestParam Integer pageNum, @RequestParam Integer pageSize){

        ResponseData res = new ResponseData();
        res.setCode(20000);
        IPage<ShopGoods> pageList = this.shopGoodsService.getShopGoodsInfo(new Page( (long)pageNum,(long)pageSize),shopGoods);
        res.setData(pageList);
//        res.setTotal(documentServiceImpl.getDocumentInfo(document).size());

        return res;

    }


    @DeleteMapping("/deleteShopGoodsInfo/{id}")
    public ResponseData deleteShopGoodsInfo( @PathVariable("id") int id){
        ResponseData res = new ResponseData();
        boolean result = shopGoodsService.removeById(id);
        if (result){
            res.setCode(20000);
            res.setData("success");

        }else{
            res.setCode(50000);
            res.setData("fail");
        }
        return res;

    }

    @PostMapping("/updateStoreroomInfo")
    public ResponseData updateStoreroomInfo(@RequestBody ShopGoods shopGoods){


        boolean result = false;
        ResponseData res = new ResponseData();



        result= shopGoodsService.saveOrUpdate(shopGoods);

        if (result){
            res.setCode(20000);
            res.setData("success");

        }else{
            res.setCode(50000);
            res.setData("fail");
        }
        return res;
    }


}
